import http from '@/utils/http'

const BASE_URL = '/testing/api'

export interface ApiResp {
  id: string
  projectId: string
  moduleId: string
  environmentId: string
  name: string
  description: string
  level: string
  path: string
  method: string
  query: string
  header: string
  body: string
  bodyType: string
  version: string
  status: string
  isDeleted: string
  createdBy: string
  updatedBy: string
  createdAt: string
  updatedAt: string
  createUserString: string
  updateUserString: string
}
export interface ApiDetailResp {
  id: string
  projectId: string
  moduleId: string
  environmentId: string
  name: string
  description: string
  level: string
  path: string
  method: string
  query: string
  header: string
  body: string
  bodyType: string
  version: string
  status: string
  isDeleted: string
  createdBy: string
  updatedBy: string
  createdAt: string
  updatedAt: string
  createUserString: string
  updateUserString: string
}
export interface ApiQuery {
  version: string
  createdBy: string
  sort: Array<string>
}
export interface ApiPageQuery extends ApiQuery, PageQuery {}

/** @desc 查询接口列表 */
export function listApi(query: ApiPageQuery) {
  return http.get<PageRes<ApiResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询接口详情 */
export function getApi(id: string) {
  return http.get<ApiDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增接口 */
export function addApi(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改接口 */
export function updateApi(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除接口 */
export function deleteApi(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出接口 */
export function exportApi(query: ApiQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}
